﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace SampleWebApplication
{
    public partial class Update : System.Web.UI.Page
    {
        Db_connect db = new Db_connect();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int _id = Convert.ToInt32(DropDownList1.SelectedItem.Text);



            String select_query = "select * from customer where id='" + _id + "'";
            try
            {

                DataSet _ds = new DataSet();
                _ds = db.GetDataSet(select_query);

                TextBox6.Text = _ds.Tables[0].Rows[0][0].ToString();
                TextBox7.Text = _ds.Tables[0].Rows[0][1].ToString();
                TextBox8.Text = _ds.Tables[0].Rows[0][2].ToString();
                TextBox9.Text = _ds.Tables[0].Rows[0][3].ToString();



            }
            catch (Exception ex)
            {
                Label3.Text = ex.Message;
            }


        }    

        protected void Button3_Click(object sender, EventArgs e)
        {
            String name = TextBox6.Text;
            String address = TextBox7.Text;
            String bdate = TextBox8.Text;
            String age = TextBox9.Text;

            int _id = Convert.ToInt32(DropDownList1.SelectedItem.Text);

            try
            {
                String update_query = "update customer set name='" + name + "',address='" + address + "',birthdate='" + bdate + "',age='"+age+"' where id='" + _id + "'";
               
                bool check= db.insertDeleteUpdateValues(update_query);

                if (check)
                {
                    Label3.Text = "Update Complete";
                    Response.Redirect("WebForm1.aspx");
                }

            }
            catch (Exception ex)
            {
                Label3.Text = ex.Message;
            }
        }
    }
}